import Base from './Base'
import Page from './Page'
import ProductAttachmentType from './ProductAttachmentType'

class ProductAttachment extends Base {
  constructor ({
    id = '',
    product = {id: '', name: ''},
    name = '',
    path = '',
    productAttachmentType = new ProductAttachmentType({}),
    contentType = '',
    size = ''
  }) {
    super({id})

    this.product = product
    this.name = name
    this.path = path
    this.productAttachmentType = new ProductAttachmentType(productAttachmentType)
    this.contentType = contentType
    this.size = size
  }

  static async find (params) {
    let {content, ...pagination} = await ProductAttachment.$http.get(`${ProductAttachment.$name}/listByProductId`, {params})
    content = content.map(v => new this(v))
    pagination = new Page(pagination)
    return {content, pagination}
  }
}
// 静态属性
ProductAttachment.$name = '/product/attachement'
export default ProductAttachment
